package com.applancer.parser;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.applancer.model.GeneralModel;
import com.applancer.model.MenuModel;

public class MenuParser extends GeneralParser {

	@Override
	public GeneralModel parseModel(JSONObject obj) {

		MenuModel model = new MenuModel();

		try {
			model.setID(obj.getString("ID"));
		} catch (Exception e) {
		}

		try {
			model.setObject_id(obj.getString("object_id"));
		} catch (Exception e) {
		}

		try {
			model.setTitle(obj.getString("title"));
		} catch (Exception e) {
		}

		try {
			model.setObject(obj.getString("object"));
		} catch (Exception e) {
		}

		if (model.getObject().equals("page")
				&& !model.getTitle().equals("Home"))
			return null;

		try {
			model.setUrl(obj.getString("url"));
		} catch (Exception e) {
		}

		try {
			model.setLevel(obj.getString("level"));
		} catch (Exception e) {
		}

		try {
			JSONArray jarray = obj.getJSONArray("childs");

			if (jarray == null || jarray.length() == 0) {
				model.setChilds(new ArrayList<GeneralModel>());
			} else
				model.setChilds(parseData(jarray));
		} catch (Exception e) {

		}
		return model;

	}
}
